package com.lagou.edu.utils;
/*
 * PackageName: com.lagou.edu.utils
 * ClassName:   FileScanUtil
 * Author:   coke
 * Date:     Created in 2020/10/17 12:02
 * Description:
 * History:
 * <author>        <time>             <version>          <desc>
 * 作者姓名         修改时间            版本号              描述
 * coke           2020/10/17 12:02     1.0
 */

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangKe
 * @Project lagou-transfer-iocxml
 * @Description
 * @date 2020/10/17 12:02.
 */
public class FileScanUtil {

    public static List<String> filePath = new ArrayList<>();

    /**
     * 获取所有类的全限定类名List
     * @return
     */
    public static List<String> getFilePath() {
        return filePath;
    }

    public static String getRootPath() throws IOException {
        return FileScanUtil.class.getResource("/").getPath();
    }

    /**
     * 获取所有类的全限定类名
     * @param rootPath  项目根路径，根据getRootPath()传入
     */
    public static List<String> getClassPath(String rootPath) throws IOException {
        final File[] files = new File(rootPath).listFiles();
        for (File file : files) {
            if (file.isDirectory())
                getClassPath(file.getPath());
            else
                if (file.getName().endsWith(".class")){
                    String fileName = file.getPath().replaceAll("\\\\",".").substring(file.getPath().indexOf("com\\lagou"));
                    filePath.add(fileName.substring(0,fileName.indexOf(".class")));
                }
        }
        return filePath;
    }
}
